</div>
        <script src="../public/bootstrap-5.3.0-alpha1-dist/js/bootstrap.bundle.min.js"></script>
        <script>
            document.addEventListener('DOMContentLoaded', function() {
                // 处理所有密码切换按钮
                document.querySelectorAll('.toggle-password').forEach(toggleButton => {
                    toggleButton.addEventListener('click', function() {
                        // 查找关联的密码输入框
                        const passwordInput = this.previousElementSibling || 
                                            this.closest('.input-group')?.querySelector('input[type="password"], input[type="text"]') || 
                                            document.getElementById(this.getAttribute('data-target'));
                        
                        if (!passwordInput) return;
                        
                        // 获取图标元素
                        const eyeIcon = this.querySelector('i');
                        
                        // 切换密码可见性
                        const isPassword = passwordInput.type === 'password';
                        passwordInput.type = isPassword ? 'text' : 'password';
                        
                        // 切换图标
                        if (isPassword) {
                            eyeIcon.classList.remove('bi-eye');
                            eyeIcon.classList.add('bi-eye-slash');
                        } else {
                            eyeIcon.classList.remove('bi-eye-slash');
                            eyeIcon.classList.add('bi-eye');
                        }
                    });
                });
                
                // 动态显示自定义问题输入框 (添加用户页面)
                const securityQuestionEl = document.getElementById('securityQuestion');
                if (securityQuestionEl) {
                    securityQuestionEl.addEventListener('change', function() {
                        const container = document.getElementById('customQuestionContainer');
                        if (!container) return;
                        
                        const customInput = container.querySelector('input');
                        
                        if (this.value === '自定义问题') {
                            container.style.display = 'block';
                            if (customInput) customInput.setAttribute('required', true);
                            
                            // 添加自定义问题时自动聚焦
                            if (customInput && !customInput.value.trim()) {
                                customInput.focus();
                            }
                        } else {
                            container.style.display = 'none';
                            if (customInput) customInput.removeAttribute('required');
                        }
                    });
                }
                
                // 动态显示自定义问题输入框 (其他页面)
                const securityQuestionEl2 = document.getElementById('security_question');
                if (securityQuestionEl2) {
                    securityQuestionEl2.addEventListener('change', function() {
                        const container = document.getElementById('custom-question-container');
                        if (!container) return;
                        
                        if (this.value === '自定义问题') {
                            container.style.display = 'block';
                            const customInput = document.querySelector('[name="new_question_custom"]');
                            if (customInput) customInput.setAttribute('required', true);
                        } else {
                            container.style.display = 'none';
                            const customInput = document.querySelector('[name="new_question_custom"]');
                            if (customInput) customInput.removeAttribute('required');
                        }
                    });
                }
                
                // 实时密码强度验证函数
                function updatePasswordRequirements(value) {
                    const requirements = {
                        length: value.length >= 8,
                        lowercase: /[a-z]/.test(value),
                        uppercase: /[A-Z]/.test(value),
                        number: /\d/.test(value)
                    };

                    // 更新气泡框内的提示
                    Object.keys(requirements).forEach(key => {
                        const element = document.getElementById('popover-'+key);
                        if (element) {
                            const isValid = requirements[key];
                            element.classList.toggle('text-success', isValid);
                            element.classList.toggle('text-danger', !isValid);
                            const icon = element.querySelector('i');
                            if (icon) {
                                icon.className = isValid ? 'bi bi-check-circle-fill' : 'bi bi-x-circle-fill';
                            }
                        }
                    });
                }
                
                // 初始化密码强度气泡框
                const passwordInput = document.getElementById('passwordInput');
                if (passwordInput) {
                    const popover = new bootstrap.Popover(passwordInput, {
                        container: 'body',
                        customClass: 'password-popover custom-popover',
                        sanitize: false
                    });
                    
                    // 气泡框显示时更新内容
                    passwordInput.addEventListener('shown.bs.popover', function() {
                        updatePasswordRequirements(this.value);
                    });
                    
                    passwordInput.addEventListener('input', function(e) {
                        updatePasswordRequirements(e.target.value);
                        
                        // 如果Popover已显示，更新内容
                        if (popover._element.getAttribute('aria-describedby')) {
                            updatePasswordRequirements(e.target.value);
                        }
                    });
                    
                    // 初始化验证
                    updatePasswordRequirements(passwordInput.value);
                }
            });
        </script>
    </body>
</html>